package com.lli.mc.converter.openoffice;

import javax.annotation.Resource;

import org.apache.commons.pool2.PoolUtils;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.stereotype.Component;

import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.lli.mc.conf.OpenOfficeConfig;

/**
 * openoffice连接池
 * 
 * @author lli
 *
 * @version 1.0
 *
 */
@Component
public class OpenOfficeConnectionPool {

    public GenericObjectPool<OpenOfficeConnection> POOL;
    @Resource
    OpenOfficeConfig openOfficeConfig; // openoffice配置文件

    /**
     * 初始化连接池
     * 
     * @description
     * @author lli
     * @create 2017年7月26日下午2:39:04
     * @version 1.0
     * @throws Exception
     */
    public void initPool() throws Exception {
        GenericObjectPoolConfig conf = new GenericObjectPoolConfig();
        conf.setMaxTotal(5);
        conf.setMinIdle(5);
        conf.setMaxIdle(5);
        POOL = new GenericObjectPool<OpenOfficeConnection>(
                new OpenOfficeConnectionFactory(openOfficeConfig.getHost(),
                        openOfficeConfig.getPort()), conf);
        // 初始化线程池对象大小
        PoolUtils.prefill(POOL, 1);
    }
}
